﻿using DDD.Application.Services;
using DDD.Domain.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApp.Controllers
{
    public class HomeController : Controller
    {
        private IStudentService _studentService;

        public HomeController(IStudentService studentService)
        {
            _studentService = studentService;
        }

        public ActionResult Index()
        {
            var list = _studentService.Find(x => x.ID != 0);
            return View(list);
        }

        [HttpPost]
        public ActionResult Insert(FormCollection from)
        {
            var Name = from["Name"];
            var Email = from["EmailAddress"];
            _studentService.Insert(new Student { Name = Name, EmailAddress = Email });
            return RedirectToAction("Index");
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}